# Copyright (C) 2007 Laszlo Pandy <laszlok2@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

import unittest
from AdventureMoney.core import Person

class TestCase(unittest.TestCase):
	
	nameA = "Jim"
	nameB = "Alice Bob"
	
	def setUp(self):
		self.personA = Person.Person(self.nameA)
		self.personB = Person.Person(self.nameB)
		self.personAdup = Person.Person(self.nameA)
		
	def testHash(self):
		hashA = hash(self.personA)
		hashB = hash(self.personB)
		hashAdup = hash(self.personAdup)
		
		self.assertEqual(hashA, hashAdup)
		self.assertNotEqual(hashA, hashB)
		self.assertNotEqual(hashB, hashAdup)
		
	def testStr(self):
		strA = str(self.personA)
		strB = str(self.personB)
		strAdup = str(self.personAdup)
		
		self.assertEqual(strA, strAdup)
		self.assertNotEqual(strA, strB)
		self.assertNotEqual(strB, strAdup)
		
	def testRepr(self):
		try:
			repr(self.personA)
		except Exception, e:
			self.fail(repr(e))
		
	def testCmp(self):
		# compare with each other
		self.assertEqual(self.personA, self.personAdup)
		self.assertNotEqual(self.personA, self.personB)
		self.assertNotEqual(self.personB, self.personAdup)
		self.assertNotEqual(self.personB, "")
		
		#compare with names
		self.assertEqual(self.personA, self.nameA)
		self.assertEqual(self.personA, self.nameA.lower())
		self.assertEqual(self.personB, self.nameB)
		self.assertEqual(self.personAdup, self.nameA)
		
		#compare with other strings
		self.assertNotEqual(self.personA, self.nameA + "d")
		self.assertNotEqual(self.personB, self.nameB + "n")
		
	def testCopy(self):
		copyA = self.personA.copy()
		copyB = self.personB.copy()
		
		self.assertEqual(self.personA, copyA)
		self.assertEqual(self.personB, copyB)
		self.assertEqual(copyA, self.personAdup)
		self.assertNotEqual(copyA, copyB)
		
	def testGetName(self):
		self.assertEqual(self.personA.getName(), self.nameA)
		self.assertEqual(self.personB.getName(), self.nameB)
		self.assertEqual(self.personAdup.getName(), self.nameA)
	
	def tearDown(self):
		pass
